﻿using System;
using System.Collections.ObjectModel;
using Trentacular.SharePoint.Deployment.Data;

namespace Trentacular.SharePoint.Deployment.Views
{
    public abstract class BaseViewComponent<TParent> : BaseViewComponent where TParent : BaseViewComponent
    {
        public new TParent Parent
        {
            get { return (TParent)base.Parent; }
            set { base.Parent = value; }
        }
    }

    public abstract class BaseViewComponent
    {
        private BaseView _view;
        public BaseView View
        {
            get
            {
                if (_view != null)
                    return _view;

                return Parent.View;
            }
            set { _view = value; }
        }

        public BaseViewComponent Parent { get; set; }

        protected AppData Data { get { return View.Data; } }

        protected void DoWorkAsync<T>(Action<T> action, Action<T> callback, T state)
        {
            View.DoWorkAsync(action, callback, state);
        }

        protected void FillCollectionAsync<T>(ObservableCollection<T> collection, RetrieveEnumerableAction<T> action)
        {
            View.FillCollectionAsync(collection, action);
        }
    }
}
